package com.gnerv.sylvanas.framework.core.listener;

import com.gnerv.sylvanas.framework.core.listener.service.BaseApplicationStartedService;
import jakarta.annotation.Nonnull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;


/**
 * 应用启动后执行
 *
 * @author Gnerv LiGen
 */
@Slf4j
@Component
public class BaseApplicationStartedEventListener implements ApplicationListener<ApplicationStartedEvent> {

    @Override
    public void onApplicationEvent(@Nonnull ApplicationStartedEvent applicationStartedEvent) {
        applicationStartedEvent.getApplicationContext()
                .getBeansOfType(BaseApplicationStartedService.class)
                .forEach((beanName, baseApplicationStartedService) -> baseApplicationStartedService.handle(applicationStartedEvent));
    }

}
